package com.smartrobot.robot;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;

import com.smartrobot.constant.Constants;
import com.smartrobot.conversation.ContainerPool;
import com.smartrobot.dispatcher.AbstractDispatcher;
import com.smartrobot.dispatcher.GtalkDispatcher;
import com.smartrobot.dispatcher.UserRequest;
import com.smartrobot.dispatcher.UserResponse;

public class GtalkRobotListener implements MessageListener{

	
//	private static Logger log=Logger.getLogger(GtalkRobotListener.class);

	@Override
	public void processMessage(Chat chat, Message message) {
		ContainerPool pool=ContainerPool.getPool();
		AbstractDispatcher gtalkDispatcher=pool.getDispatcher();
		if(gtalkDispatcher==null){
			gtalkDispatcher=new GtalkDispatcher();
		}
		UserRequest request=new GtalkUserRequest();
		request.setAttribute(Constants.GTALK_CHAT, chat);
		request.setAttribute(Constants.GTALK_MESSAGE, message);
		
		UserResponse response=new GtalkUserResponse();
		response.setAttribute(Constants.GTALK_CHAT, chat);
		gtalkDispatcher.setRequest(request);
		gtalkDispatcher.setResponse(response);
		pool.prcessMessage(gtalkDispatcher);

	}

}
